package cn.vconinfo.base.observe;

import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.lang.NonNull;
import org.springframework.scheduling.annotation.Async;

@RequiredArgsConstructor
public class ObserverListener implements ApplicationListener<ObserverEvent> {

    @NonNull
    private String name;

    private String article;

    @Async
    @Override
    public void onApplicationEvent(ObserverEvent observerEvent) {
        updateArticle(observerEvent);
    }

    private void updateArticle(ObserverEvent event){
        this.article = (String) event.getSource();
        System.out.printf("这是最终输出结果的地方：%s, %s", this.name, this.article);
    }
}
